package com.example.hilt_mvvm_http.viewmodel

import com.example.hilt_mvvm_http.base.BaseViewModel
import com.example.hilt_mvvm_http.base.Failed
import com.example.hilt_mvvm_http.base.Loading
import com.example.hilt_mvvm_http.base.RequestEvent
import com.example.hilt_mvvm_http.base.Success
import com.example.hilt_mvvm_http.one.model.BaseModel
import com.example.hilt_mvvm_http.one.model.UpdateModel
import com.example.hilt_mvvm_http.respository.MainRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import retrofit2.http.Query
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor(private val repository:MainRepository):BaseViewModel() {

    private val _appUpdateShareFlow = MutableSharedFlow<RequestEvent>()
    val appUpdateShareFlow:SharedFlow<RequestEvent>
        get() = _appUpdateShareFlow.asSharedFlow()

    /**
     * 第一套接口：版本是否需要更新
     */
    fun appUpdate(){
        execute(
            action = repository.appUpdate(),
            onStart = {
                _appUpdateShareFlow.emit(Loading)

            },
            onFinished = {
                _appUpdateShareFlow.emit(Success)
            },
            onError = {
                _appUpdateShareFlow.emit(Failed(it))
            }
        )
    }
}